import { Application } from 'egg';
import {
  indexRule,
  createRule,
  updateRule,
  destroyRule,
 } from '../validate/platform/store/mini';

/**
 * 小程序页面管理
 */
export default (app: Application) => {
  const { auth } = app.middleware;
  const {  jwt } = app;

  return {
    'store.mini_my_list': {
      method: 'GET',
      path: '/api/store/mini/mylist',
      options: {
        tags: ['list/list'],
        description: '我的小程序页面列表',
        handler: app.controller.platform.store.mini.myList,
        middlewares: [jwt, auth('store.mini_my_list')],
        validate: indexRule,
      },
    },
    'store.mini_list': {
      method: 'GET',
      path: '/api/store/mini/list',
      options: {
        tags: ['list/list'],
        description: '小程序页面列表',
        handler: app.controller.platform.store.mini.list,
        middlewares: [jwt, auth('store.mini_list')],
        validate: indexRule,
      },
    },
    'store.mini_create': {
      method: 'POST',
      path: '/api/store/mini/list',
      options: {
        tags: ['list/create'],
        description: '创建小程序页面',
        handler: app.controller.platform.store.mini.create,
        middlewares: [jwt, auth('store.mini_create')],
        validate: createRule,
      },
    },
    'store.mini_update': {
      method: 'PUT',
      path: '/api/store/mini/:id',
      options: {
        tags: ['list/update'],
        description: '更新小程序页面',
        handler: app.controller.platform.store.mini.update,
        middlewares: [jwt, auth('store.mini_update')],
        validate: updateRule,
      },
    },
    'store.mini_destroy': {
      method: 'DELETE',
      path: '/api/store/mini/:id',
      options: {
        tags: ['list/delete'],
        description: '删除小程序页面',
        handler: app.controller.platform.store.mini.destroy,
        middlewares: [jwt, auth('store.mini_destroy')],
        validate: destroyRule,
      },
    },
  };
};
